let tabel = $("#prodetail");
$(document).ready(function () {
    // 设置表格文本内容居中
    tabel.css("text-align", "center");
    getNowData();
    $("#queryBtn").click(function () {
        let province = $("#proinput").val();
        let date = $("#createTime").val();
        if(province == ''&& date !== '')
            GetDataByDate(date);
        else if(province !== ''&& date !== '')
            GetDataByNameAndDate(province,date);
        else
            getNowData();
    })
})

//获取指定日期和省份的所有数据
function GetDataByNameAndDate(name,date){
    let url="province?method=queryPro"+ "&date=" + date + "&name=" + name;
    $.get(url, function (data, status) {
        $("#prodetail tbody").html("");//清空表内数据
        let chinesename = data["chinesename"];
        let currentConfirmedCount = data["currentConfirmedCount"];
        let UsercuredName = data["cured"];
        let dead = data["dead"];
        let suspected = data["suspected"];
        let tr = tabel.append(`<tr>
                <td>${chinesename}</td>
                <td>${currentConfirmedCount}</td>
                <td>${UsercuredName}</td>
                <td>${dead}</td>
                <td>${suspected}</td>
            </tr>`);
    })
}

//获取指定日期的所有数据
function GetDataByDate(date){
    let url_get = "province?method=queryProvinceJson&date="+date;
    $.get(url_get, function (data, status) {
        $("#prodetail tbody").html("");//清空表内数据
        for (let item of data) {
            let chinesename = item["chinesename"];
            let currentConfirmedCount = item["currentConfirmedCount"];
            let UsercuredName = item["cured"];
            let dead = item["dead"];
            let suspected = item["suspected"];
            // 将每行数据挂载在dom树tbody节点下
            let tr = tabel.append(`<tr>
                    <td>${chinesename}</td>
                    <td>${currentConfirmedCount}</td>
                    <td>${UsercuredName}</td>
                    <td>${dead}</td>
                    <td>${suspected}</td>
                </tr>`);
        }
    })
}

//获取当前日期的数据
function getNowData() {
    let url_get = "province?method=queryNowProvinceJson";
    $.get(url_get, function (data, status) {
        $("#prodetail tbody").html("");//清空表内数据
        for (let item of data) {
            let chinesename = item["chinesename"];
            let currentConfirmedCount = item["currentConfirmedCount"];
            let UsercuredName = item["cured"];
            let dead = item["dead"];
            let suspected = item["suspected"];
            // 将每行数据挂载在dom树tbody节点下
            let tr = tabel.append(`<tr>
                    <td>${chinesename}</td>
                    <td>${currentConfirmedCount}</td>
                    <td>${UsercuredName}</td>
                    <td>${dead}</td>
                    <td>${suspected}</td>
                </tr>`);
        }
    })
}